<?php
  require_once("konf.php");
  if(isSet($_REQUEST["hipodroomi_nimi"])){
  $kask=$yhendus->prepare("SELECT hipodroomi_nimi FROM hipodroomid WHERE hipodroomi_nimi=?");
  $kask->bind_param("s", $_REQUEST["hipodroomi_nimi"]);
  $kask->bind_result($hipodroomi_nimi);
  $kask->execute();
  }
?>
<!doctype html>
<html>
  <head>
    <title>Hipodroomi andmed</title>
	<link href="kujundus.css" rel="stylesheet" type="text/css" />
	<meta charset="UTF-8">
  </head>
  <body>
  <div id="pealkiri">
  <h1>Hipodroomi andmed</h1>
  </div>
  <div id="main_container">
  <?php
    while($kask->fetch()){
		    $hipodroomi_nimi=htmlspecialchars($hipodroomi_nimi);
		    echo "
			  <h1>$hipodroomi_nimi</h1>
				  
	
			";
		 }
		 $kask->close();
	  
	?> 	 
 <h2>Hetkel siin elavad hobused</h2>
   <table>
       <tr>
         <th>Hobuse nimi</th>
         <th>Tall</th>
         <th>Latter</th>
       </tr>
    <?php   
	  if(isSet($_REQUEST["hipodroomi_nimi"])){
	   $kask=$yhendus->prepare("SELECT hipodroomi_nimi, hobused.hobune_ID, hobune_nimi, talli_nr, latri_nr FROM hobused, elamine, latrid, tallid, hipodroomid WHERE tallid.hipodroom_ID=hipodroomid.hipodroom_ID AND latrid.tall_ID=tallid.tall_ID AND elamine.hobune_ID=hobused.hobune_ID AND elamine.latter_ID=latrid.latter_ID AND v2lja>NOW() AND  hipodroomi_nimi=?
	                             ORDER BY talli_nr, latri_nr" );
	   echo $yhendus->error;
       $kask->bind_param("s", $_REQUEST["hipodroomi_nimi"]);
       $kask->bind_result($hipodroomi_nimi, $hobune_ID, $hobune_nimi, $talli_nr, $latri_nr);
       $kask->execute();
	  
	while($kask->fetch()){
	     echo "
		<tr> 
         <td><a href='hobune.php?hobune_ID=$hobune_ID'>$hobune_nimi</a></td>
         <td>$talli_nr</td>
         <td>$latri_nr</td>	
	   </tr>
	   ";
	    }
	  }
	  $kask->close();
	?> 
	</table>
	 <h2>Siin toimunud võistlused</h2>
   <table>
       <tr>
	     <th>Võistluse nimi</th>
	   </tr>
    <?php
	   if(isSet($_REQUEST["hipodroomi_nimi"])){
	     $kask=$yhendus->prepare("SELECT hipodroomi_nimi, voistlus_ID, voistluse_nimi FROM voistlused, hipodroomid WHERE voistlused.hipodroom_ID=hipodroomid.hipodroom_ID AND hipodroomi_nimi=? ");
		 $kask->bind_param("s", $_REQUEST["hipodroomi_nimi"]);
         $kask->bind_result($hipodroomi_nimi, $voistlus_ID, $voistluse_nimi);
         $kask->execute();
        while($kask->fetch()){
		  $voistluse_nimi=htmlspecialchars($voistluse_nimi);
          echo "
            <tr>
              <td><a href='voistlus.php?voistlus_ID=$voistlus_ID'>$voistluse_nimi</a></td>
            </tr>
           ";
       }
	  }
	   $kask->close();
    ?>
   </table>

	<p><a href="statistika.php">Tagasi avalehele</a></p>
	</div>
  </body>
</html>